<?php

declare(strict_types=1);

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class ProductRange extends Model
{
    protected $table = 'product_ranges';

    public static function getCityProductIds(int $cityId)
    {
        $productIds = [];
        $where      = [
            'area_level' => 1,
        ];
        if ($cityId) {
            $where['area_code'] = $cityId;
        }
        $data = self::where($where)->get();
        if ($data && $data = $data->toArray()) {
            $productIds = array_column($data, 'product_id');
            $productIds = array_values(array_unique(array_filter($productIds)));
        }

        return $productIds;
    }
}
